package com.key.sys.tags;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import com.key.model.User;
import com.key.sys.privilege.SystemPrivilege;
import com.key.sys.privilege.SystemPrivilegePK;

public class PermissionTag extends TagSupport {
   //模块
   private String module;
   //模块中具体权限
   private String action;
 
   public String getModule() {
      return module;
   }
   public void setModule(String module) {
      this.module = module;
   }

   public String getAction() {
	return action;
}
public void setAction(String action) {
	this.action = action;
}
@Override
   public int doStartTag() throws JspException {
      boolean result = false;
      User user = (User)((HttpServletRequest) pageContext.getRequest()).getSession().getAttribute("user");//WebUtil是自定义的工具类，获取此时登陆的用户
      SystemPrivilege privilege = new SystemPrivilege(user,new SystemPrivilegePK(this.module,this.action));
      result = privilege.isPremission();
      return result? EVAL_BODY_INCLUDE : SKIP_BODY;//真：返回EVAL_BODY_INCLUDE（执行标签）；假：返回SKIP_BODY（跳过标签不执行）
   }
}